﻿<sticky:StickyWindowBase xmlns:sticky="clr-namespace:Squiggle.UI.StickyWindow"
                     x:Class="Squiggle.UI.Windows.ContactsSelectWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:converters="clr-namespace:Squiggle.UI.Converters"
        xmlns:chat="clr-namespace:Squiggle.Client;assembly=Squiggle.Client"
        xmlns:controls="clr-namespace:Squiggle.UI.Controls" KeyDown="Window_KeyDown"
        Icon="/Squiggle;component/Images/Chat.ico"                      
        Height="500" Width="360" x:Name="contactSelectControl" WindowStartupLocation="CenterOwner" ShowInTaskbar="False">
    <sticky:StickyWindowBase.Resources>
        <CollectionViewSource Source="{Binding Buddies}" x:Key="buddiesCollection" Filter="CollectionViewSource_Filter" />
        <converters:StatusIconConverter x:Key="statusIconConverter" />
        <converters:StatusConverter x:Key="statusConverter" />
        <BooleanToVisibilityConverter x:Key="visibilityConverter"/>
        <DataTemplate DataType="{x:Type chat:Buddy}">
            <Border x:Name="contactBorder" Padding="1" Cursor="Hand"
                    Tag="{Binding}" MouseLeftButtonUp="contactBorder_MouseLeftButtonUp">
                <Border.ToolTip>
                    <ToolTip Style="{StaticResource BuddyToolTip}" />
                </Border.ToolTip>
                <Grid Margin="5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="30"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="0.01*"/>
                    </Grid.RowDefinitions>
                    <CheckBox Grid.Column="0" x:Name="chkSelection" Tag="{Binding}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" Margin="0,0,10,0" Visibility="{Binding ElementName=contactSelectControl, Path=AllowMultiSelect, Converter={StaticResource visibilityConverter}}" />
                    <Image Grid.Column="1" Width="20" Height="20" Source="{Binding Path=Status, Converter={StaticResource statusIconConverter}}" VerticalAlignment="Top"/>
                    <StackPanel Orientation="Vertical" Grid.Column="2">
                        <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Margin="5,0,0,0" Cursor="Hand" >                            
                            <TextBlock Text="{Binding Path=DisplayName}" />
                            <TextBlock x:Name="buddyStatus" Margin="5,0,0,0" Text="{Binding Path=Status, Converter={StaticResource statusConverter}, StringFormat={}({0})}" />
                        </StackPanel>
                        <TextBlock Margin="5,0,0,0" Text="{Binding Path=Properties.DisplayMessage}" TextTrimming="WordEllipsis" ToolTip="{Binding Path=DisplayMessage}"  FontSize="10" Foreground="#FF9A9C9D" HorizontalAlignment="Left" />
                    </StackPanel>
                </Grid>
            </Border>
            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding Status}" Value="Online">
                    <Setter TargetName="buddyStatus" Property="Visibility" Value="Hidden" />
                </DataTrigger>
                <DataTrigger Binding="{Binding Status}" Value="Offline">
                    <Setter TargetName="buddyStatus" Property="Visibility" Value="Hidden" />
                </DataTrigger>
                <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                    <Setter Property="Background" Value="White" 
                                TargetName="contactBorder"></Setter>
                </Trigger>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="WhiteSmoke" 
                                TargetName="contactBorder"></Setter>
                </Trigger>
                <Trigger SourceName="contactBorder" Property="IsMouseOver" Value="True">
                    <Setter TargetName="contactBorder" Property="Background" >
                        <Setter.Value>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FFF0F0F0" Offset="0.061"/>
                                <GradientStop Color="#FFE3E4E4" Offset="0.939"/>
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </DataTemplate.Triggers>
        </DataTemplate>
    </sticky:StickyWindowBase.Resources>
    <Grid Margin="10" x:Name="LayoutRoot" FlowDirection="{StaticResource flowDirection}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <TextBlock x:Name="txtMessage" Text="{StaticResource ContactSelectWindow_SingleSelect}" Margin="10,0,0,0" />
        <controls:FilterTextBox FilterChanged="FilterTextBox_FilterChanged" VerticalAlignment="Top" Grid.Row="1"  Width="Auto" HorizontalAlignment="Stretch" Margin="10" Height="25"/>
        <ScrollViewer Grid.Row="2" Focusable="False" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Hidden">
            <ItemsControl Focusable="False" Margin="5" DataContext="{Binding}" ItemsSource="{Binding Source={StaticResource buddiesCollection}}" AlternationCount="2"  />
        </ScrollViewer>
        <Grid Grid.Row="3">
            <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                <Button Content="{StaticResource Global_OKButton}" IsDefault="True" Width="70" Click="OnOK" Visibility="{Binding ElementName=contactSelectControl, Path=AllowMultiSelect, Converter={StaticResource visibilityConverter}}" />
                <Button IsCancel="True" Content="{StaticResource Global_CancelButton}" Width="70" Margin="5,0,0,0" Click="OnCancel" />
            </StackPanel>
        </Grid>
    </Grid>
</sticky:StickyWindowBase>
